#!/usr/bin/env python3
import sys
import re

def print_bool_matrix(matrix):
    print(f'{width} by {height} matrix')
    print('\n'.join([ ' '.join([ '#' if e else '.' for e in row ]) for row in matrix ]))

matrix = []
width = 0
height = 0
folding = False
for line in sys.stdin:
    if line == '\n':
        folding = True
        continue
    # first part
    if not folding:
        # get points
        x, y = [ int(group) for group in re.match(r'(\d+),(\d+)', line).groups() ]
        # resize if needed
        if y + 1 > height:
            for i in range(y + 1 - height):
                matrix.append([False] * width)
            height = y + 1
        if x + 1 > width:
            for row in matrix:
                for i in range(x + 1 - width):
                    row.append(False)
            width = x + 1
        matrix[y][x] = True
    # second part
    else:
        axis, stop = [ group for group in re.match(r'fold along ([xy])=(\d)', line).groups() ]
        horizontal = 'y' in axis
        stop = int(stop)
        print(f'fold by {axis}={stop}')

        if horizontal:
            # make horizontal fold
            up = matrix[0:stop]
            bottom = matrix[stop + 1:]
            bottom = bottom[::-1]

            # save fold
            matrix = [ [ u or b for u, b in zip(up_rows, bottom_rows) ] for up_rows, bottom_rows in zip(up, bottom) ]
            height = stop
        else:
            # make vertical fold
            left = [ row[0:stop] for row in matrix ]
            right = [ row[stop + 1:] for row in matrix ]
            right = [ row[::-1] for row in right ]

            # save fold
            matrix = [ [ l or r for l, r in zip(left_rows, right_rows) ] for left_rows, right_rows in zip(left, right) ]
            width = stop
    visible = sum([ len([ e for e in row if e ]) for row in matrix ])
    print(f'there are {visible} visible dots')
    print_bool_matrix(matrix)